<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统</title>
<%@include file="/WEB-INF/jsp/include/easyui_1_5_3.jsp"%>

<script type="text/javascript">
	//请求地址
	var url;
	//提示消息
	var mesTitle;

	//页面加载后执行
	$(function(){
		//设置排序
        $("#datagrid").datagrid("sort",{
        	sortName: 'num', sortOrder: 'asc'
        });
		$('#pcode_form').combotree({
			url: path+'/sysMenu/getMenuBy',
			panelHeight: '120',
			editable: 'true',
// 			valueField:'code',
// 			textField:'name',
// 			keyHandler: function(q, row){//需要扩展才能实现：easyui  树形选择框 根据输入筛选
// 			    var opts = $(this).combotree('options');
// 			    var r = false ;
// 			    if(row['id']){
// 			    	r = row[opts.textField].indexOf(q) >= 0 || 
// 			    		row['id'].indexOf(q) >= 0 || 
// 			    		row['id'].indexOf(q.toUpperCase()) >= 0;
// 			    }else{
// 			    	r = row[opts.textField].indexOf(q) >= 0 || 
// 			    		row['id'].indexOf(q) >= 0 ;
// 			    }
// 			    return r;
// 			},
			onSelect: function(rec){
			}
		});
		$('#ismenu_form').combobox({
			url: path+'/sysDict/kvByType?pid=isno',
			panelHeight: '120',
			valueField:'code',
			textField:'name',
			filter: function(q, row){
			    var opts = $(this).combobox('options');
			    var r = false ;
			    if(row['code']){
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q.toUpperCase()) >= 0;
			    }else{
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 ;
			    }
			    return r;
			},
			onSelect: function(rec){
			}
		});
		$('#status_form').combobox({
			url: path+'/sysDict/kvByType?pid=zt',
			panelHeight: '120',
			valueField:'code',
			textField:'name',
			filter: function(q, row){
			    var opts = $(this).combobox('options');
			    var r = false ;
			    if(row['code']){
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q.toUpperCase()) >= 0;
			    }else{
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 ;
			    }
			    return r;
			},
			onSelect: function(rec){
			}
		});
		$('#isopen_form').combobox({
			url: path+'/sysDict/kvByType?pid=isno',
			panelHeight: '120',
			valueField:'code',
			textField:'name',
			filter: function(q, row){
			    var opts = $(this).combobox('options');
			    var r = false ;
			    if(row['code']){
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q.toUpperCase()) >= 0;
			    }else{
			    	r = row[opts.textField].indexOf(q) >= 0 || 
			    		row['code'].indexOf(q) >= 0 ;
			    }
			    return r;
			},
			onSelect: function(rec){
			}
		});
    });
	//添加用户信息
	function addSysMenu(){
		$('#dlg').dialog('open').dialog('setTitle','新增');
		$('#fm').form('clear');
		url=path+"/sysMenu/add";
		mesTitle = '新增成功';
	}
	
	//编辑用户信息
 	function editSysMenu(){
	 	var row = $('#datagrid').datagrid('getSelected');
	 	if (row){
	 		var code = row.code;
		 	$('#dlg').dialog('open').dialog('setTitle','编辑');
		 	$('#fm').form('load',row);
// 		 	url = path+"/sysMenu/modify?code="+code;
		 	url = path+"/sysMenu/modify";
		 	mesTitle = '编辑成功';
	 	}else{
	 		$.messager.alert('提示', '请选择要编辑的记录！', 'error');
	 	}
	}
 	
	//删除用信息
 	function deleteSysMenu(){
	 	var row = $('#datagrid').datagrid('getSelected');
	 	if (row){
	 		var code = row.code;
		 	$('#dlg_delete').dialog('open').dialog('setTitle','删除');
		 	$('#fmdelete').form('load',row);
		 	url = path+"/sysMenu/delete?code="+code;
		 	mesTitle = '删除成功';
	 	}else{
	 		$.messager.alert('提示', '请选择要删除的记录！', 'error');
	 	}
	}
 	
	//保存添加、修改内容
	function saveSysMenu(){
		MaskUtil.mask();
// 		alert(url);
	 	$('#fm').form('submit',{
		 	url: url,
		 	onSubmit: function(){
		 		return $(this).form('validate');
		 	},
			success: function(result){
				MaskUtil.unmask();
				/* console.info(result); */
				var result = eval('('+result+')');
				if (result.success){
				 	$('#dlg').dialog('close'); 
				 	$('#datagrid').datagrid('reload'); 
				} else {
					 mesTitle = '新增失败';
				}
				$.messager.show({ 
					 title: mesTitle,
					 msg: result.msg
				});
			}
	 	});
	}	
	
	//提交删除内容
	function saveSysMenu_del(){
	 	$('#fmdelete').form('submit',{
		 	url: url,
		 	onSubmit: function(){
		 		return $(this).form('validate');
		 	},
			success: function(result){
				/* console.info(result); */
				var result = eval('('+result+')');
				if (result.success){
				 	$('#dlg_delete').dialog('close'); 
				 	$('#datagrid').datagrid('reload'); 
				} else {
					 mesTitle = '新增失败';
				}
				$.messager.show({ 
					 title: mesTitle,
					 msg: result.msg
				});
			}
	 	});
	}

	//快速查询
 	function searchSysMenuQ(){
	 	$("#datagrid").datagrid("load", {
            "username": $('#search_username').val()
        });
	}
	
	//查询
//  	function searchSysMenu(){
// 		$('#dlgsearch').dialog('open').dialog('setTitle','查询');
// 		$('#fmsearch').form('clear');
// 		url = path+"/user/searchUser";
// 		mesTitle = '查询成功';
// 	}
	
	//刷新
	function reload(){
		$('#datagrid').datagrid('reload'); 
	}
</script>

</head>
<body class="easyui-layout" fit="true">
	<div region="center" border="false" style="overflow: hidden;">
		<!-- 信息列表 title="管理" -->
		<table id="datagrid" class="easyui-datagrid" 
		    fit="true"
			url="${path}/sysMenu/datagrid" 
			toolbar="#toolbar" 
			pagination="true"
			fitColumns="false" 
			singleSelect="false" 
			rownumbers="true"
			sortName="num asc"
			sortOrder="asc"
			striped="true"
			border="false" 
			nowrap="false">
			<thead>
				<tr>
					<th field="code" width="100">系统功能</th>
					<th field="num" width="100">菜单排序号</th>
					<th field="pcode" width="100">上级菜单</th>
					<th field="pcodes" width="100">上级菜单</th>
					<th field="name" width="100">菜单名称</th>
					<th field="icons" width="100">菜单图标</th>
					<th field="url" width="100">url地址</th>
					<th field="levels" width="100">菜单层级</th>
					<th field="ismenuName" width="100">是否是菜单（1：是  0：不是）</th>
					<th field="statusName" width="100">菜单状态 :  1:启用   0:不启用</th>
					<th field="isopenName" width="100">是否打开:1:打开   0:不打开</th>
					<th field="handle" width="100">操作人</th>
					<th field="handle_date" width="100">操作时间</th>
					<th field="tips" width="100">备注</th>
					<th field="ismenu" width="100" hidden="true">是否是菜单（1：是  0：不是）</th>
					<th field="status" width="100" hidden="true">菜单状态 :  1:启用   0:不启用</th>
					<th field="isopen" width="100" hidden="true">是否打开:1:打开   0:不打开</th>

				</tr>
			</thead>
		</table>

		<!-- 按钮 -->
		<div id="toolbar">
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-reload" plain="true" onclick="reload();">刷新</a>
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" onclick="addSysMenu();">新增</a> 
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" onclick="editSysMenu();">编辑</a> 
			<a href="javascript:void(0);" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" onclick="deleteSysMenu();">删除</a>
			<span>用户名:</span><input name="search_username" id="search_username" value="" size=10 /> 
  			<a href="javascript:searchSysMenuQ()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a> 
<!-- 			<a href="javascript:void(0);" class="easyui-linkbutton" -->
<!-- 				iconCls="icon-jright" plain="true" onclick="searchSysMenu();">更多查询</a> -->
		</div>

		<!-- 添加/修改对话框 -->
		<div id="dlg" class="easyui-dialog"
			style="width:600px;height:400px;padding:30px 20px" closed="true"
			buttons="#dlg-buttons">
			<form id="fm" method="post" novalidate>
				<table>
					<tr>
						<td>
							<label>系统功能:</label>
						</td>
						<td>
							<input name="code" class="easyui-validatebox" required="true">
						</td>
						<td>
							<label>菜单排序号:</label>
						</td>
						<td>
							<input name="num" class="easyui-validatebox" required="true">
						</td>
					</tr>
					<tr>
						<td>
							<label>上级菜单:</label>
						</td>
						<td>
							<select id="pcode_form" name="pcode" class="easyui-combotree" required="true" />
<!-- 							<input id="pcode_form" name="pcode" class="easyui-combobox" required="true"> -->
						</td>
						<td>
							<label>url地址:</label>
						</td>
						<td>
							<input name="url" class="easyui-validatebox" required="true">
						</td>
					</tr>
					<tr>
						<td>
							<label>菜单名称:</label>
						</td>
						<td>
							<input name="name" class="easyui-validatebox" required="true">
						</td>
						<td>
							<label>菜单图标:</label>
						</td>
						<td>
							<input name="icons" class="easyui-validatebox" required="false">
						</td>
					</tr>
					<tr>
						<td>
							<label>是否是菜单（1：是  0：不是）:</label>
						</td>
						<td>
							<input id="ismenu_form" name="ismenu" class="easyui-combobox" required="true">
						</td>
						<td>
							<label>菜单状态 :1:启用   0:不启用:</label>
						</td>
						<td>
							<input id="status_form" name="status" class="easyui-combobox" required="true">
						</td>
					</tr>
					<tr>
						<td>
							<label>是否打开:1:打开   0:不打开:</label>
						</td>
						<td>
							<input id="isopen_form" name="isopen" class="easyui-combobox" required="true">
						</td>
						<td>
						</td>
						<td>
						</td>
					</tr>
<!-- 					<tr> -->
<!-- 						<td> -->
<!-- 							<label>操作人:</label> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<input name="handle" class="easyui-validatebox" required="true"> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<label>菜单层级:</label> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<input name="levels" class="easyui-validatebox" required="true"> -->
<!-- 						</td> -->
<!-- 					</tr> -->
<!-- 					<tr style="display:none"> -->
<!-- 						<td> -->
<!-- 							<label>操作时间:</label> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<input name="handle_date" class="easyui-datebox" required="false"> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<label>上级菜单:</label> -->
<!-- 						</td> -->
<!-- 						<td> -->
<!-- 							<input name="pcodes" class="easyui-validatebox" required="true"> -->
<!-- 						</td> -->
<!-- 					</tr> -->
					<tr >
						<td>
							<label>备注:</label>
						</td>
						<td colspan="3">
							<input name="tips" class="easyui-validatebox" required="false">
						</td>
					</tr>

				</table>
			</form>
		</div>
		
		<!-- 添加/修改对话框按钮 -->
		<div id="dlg-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton c6"
				iconCls="icon-ok" onclick="saveSysMenu()" style="width:90px">保存</a> 
				<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
				style="width:90px">取消</a>
		</div>
		
		<!-- 删除对话框 -->
		<div id="dlg_delete" class="easyui-dialog"
			style="width:300px;height:200px;padding:30px 20px" closed="true"
			buttons="#dlg-del-buttons">
			<div class="ftitle">请谨慎操作</div>
			<form id="fmdelete" method="post" novalidate>
					<label>确定删除吗？</label>
			</form>
		</div>
		
		<!-- 删除对话框按钮 -->
		<div id="dlg-del-buttons">
			<a href="javascript:void(0)" class="easyui-linkbutton c6"
				iconCls="icon-ok" onclick="saveSysMenu_del()" style="width:90px">删除</a> 
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-cancel" onclick="javascript:$('#dlg_delete').dialog('close')"
				style="width:90px">取消</a>
		</div>
		
		<!-- 查询对话框 -->
<!-- 		<div id="dlgsearch" class="easyui-dialog" -->
<!-- 			style="width:400px;height:380px;padding:30px 20px" closed="true" -->
<!-- 			buttons="#dlg-buttons"> -->
<!-- 			<form id="fmsearch" method="post" novalidate> -->
<!-- 				<label>权限:</label>   -->
<!--                     <span id="span1" style="display: inline-block;"></span>   -->
<!--                 </div> -->
<!-- 			</form> -->
<!-- 		</div> -->
		
		<!-- 查询对话框按钮 -->
<!-- 		<div id="dlg-buttons"> -->
<!-- 			<a href="javascript:void(0)" class="easyui-linkbutton c6" -->
<!-- 				iconCls="icon-ok" onclick="searchSysMenu()" style="width:90px">查询</a>  -->
<!-- 				<a href="javascript:void(0)" class="easyui-linkbutton" -->
<!-- 				iconCls="icon-cancel" onclick="javascript:$('#dlgsearch').dialog('close')" -->
<!-- 				style="width:90px">取消</a> -->
<!-- 		</div> -->
		
	</div>
</body>
</html>
